package com.tuo51.config;

import com.github.binarywang.wxpay.config.WxPayConfig;
import com.github.binarywang.wxpay.service.WxPayService;
import com.github.binarywang.wxpay.service.impl.WxPayServiceImpl;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


@Configuration
public class MPPayConfiguration {

    @Value("${mppay.app_id}")
    private String appId;

    @Value("${mppay.mchId}")
    private String mchId;

    @Value("${mppay.mchKey}")
    private String mchKey;

    @Value("${mppay.subAppId}")
    private String subAppId;

    @Value("${mppay.subMchId}")
    private String subMchId;

    @Value("${mppay.keyPath}")
    private String keyPath;

    @Value("MD5")
    private String signType;

    @Bean(name = "mpPayConfig")
    public WxPayConfig wxPayConfig() {
        WxPayConfig payConfig = new WxPayConfig();

        payConfig.setAppId(this.appId);
        payConfig.setMchId(this.mchId);
        payConfig.setMchKey(this.mchKey);
        payConfig.setSubAppId(this.subAppId);
        payConfig.setSubMchId(this.subMchId);
        payConfig.setKeyPath(this.keyPath);
        payConfig.setSignType(this.signType);

        return payConfig;
    }

    @Bean(name = "mpPayService")
    public WxPayService wxPayService() {
        WxPayService payService = new WxPayServiceImpl();
        payService.setConfig(wxPayConfig());
        return payService;
    }
}
